import React, { Component } from 'react'

export default class Footer extends Component {
  //识别是否全选
  handleCheckAll = (e) => {
    //e.target.checked true || false
    this.props.checkAllTodo(e.target.checked)
  }
  //清除已经完成
  clearAll = () => {
    this.props.clearAllDone()
  }
  render() {
    const { todos } = this.props
    //已完成的个数
    const doneCount = todos.reduce((prev, cur) => {
      return prev + (cur.done ? 1 : 0)
    }, 0)
    //全部
    const total = todos.length
    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={doneCount === total && total !== 0 ? true : false}
            onChange={this.handleCheckAll}
          />
        </label>
        <span>
          <span>{doneCount}/已完成</span> {total}/ 全部
        </span>
        <button className="btn btn-danger" onClick={this.clearAll}>
          清除已完成任务
        </button>
      </div>
    )
  }
}
